#include <SeqList.hpp>
#include <SLinkList.hpp>
#include <StaticList.hpp>
using std::cout;
using std::endl;

void STlinkTest();
void SLinkTest();
void SeqTest();
void Print(const int &n);

int main(int argc, const char **argv)
{

	cout << "hello world!" << '\n';

	cout << "SeqTest" << '\n';
	SeqTest();

	cout << "LinkTest" << '\n';
	SLinkTest();
	
	cout<<"STlinkTest"<<'\n';
	STlinkTest();
	return 0;
}

void STlinkTest()
{
	StaticList<char> sl;
	sl.InsertElem('A');
	sl.InsertElem('B');
	sl.InsertElem('C');
	sl.InsertElem(3,'D');
	sl.Traverse();
	cout<<endl;
	sl.DeleteElem(1);
	sl.Traverse();
}

void SLinkTest()
{
	int p[5] = {7, 5, 1, 3, 9}, a;

	SLinkList<int> llist1(p, 5), llist2(llist1), llist3;

	llist2.Traverse(Print); //测试深拷贝
	cout << endl;

	llist1.Traverse(Print);
	cout << endl;

	llist1.InsertElem(100); //在末尾插入
	llist1.Traverse(Print);
	cout << endl;

	llist1.InsertElem(3, 90); //在指定位置插入
	llist1.Traverse(Print);
	cout << endl;

	llist1.DeleteElem(2, a); //删除
	llist1.Traverse(Print);
	cout << endl;

	cout << llist1.LocateElem(5) << endl; //定位

	llist1.GetElem(6, a); //取元素
	cout << a << endl;

	llist1.SetElem(1, 80); //改值
	llist1.Traverse(Print);
	cout << endl;

	llist3 = llist1; //测试深赋值
	llist1.Traverse(Print);
	cout << endl;
}

void SeqTest()
{
	int data[10] = {1, 2, 3, 4, 5, 6, 7, 8}, k, m = 10;

	SeqList<int> SL(data, 5), SL2(SL), SL3(data, 8);
	SL2.Traverse(Print);
	cout << endl;

	cout << SL.GetLength() << endl;
	SL.Traverse(Print);
	cout << endl;

	SL.GetElem(2, k);
	cout << k << endl;

	SL.InsertElem(3, m);
	cout << SL.GetLength() << endl;
	SL.Traverse(Print);
	cout << endl;

	SL.DeleteElem(2, k);
	cout << SL.GetLength() << endl;
	SL.Traverse(Print);
	cout << endl;

	SL2 = SL3;
	SL2.Traverse(Print);
	cout << endl;
}

void Print(const int &n)
{
	std::cout << n << ' ';
}